﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using JoinParty.BLL;
using MySql.Data.MySqlClient;
using ZHDJ.Core;
using ZHDJ.WebPage;
using ZHDJ.Data.Models.Org;

namespace JoinParty.Template
{
    public partial class TJoinStep25 : TemplatePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

            if (!IsPostBack)
            {


                LoadData();
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            if (PartyOrgMember == null || PartyJoinApplycation == null)
                return;
            WordBusiness.Export(this, palWord, PartyOrgMember.UserName + "--组织员谈话.doc");
        }

        public void LoadData()
        {
            if (PartyOrgMember == null || PartyJoinApplycation == null)
                return;
            DataTable dt = GetJy();
            if (dt.Rows.Count == 0)
            {
                return;
            }
            litJy.Text = dt.Rows[0]["MeetingContent"].ToString();
            litMeeting.Text = Convert.ToDateTime(dt.Rows[0]["MeetingTime"].ToString()).ToLongDateString();
            litTanhua.Text = GetTanhua();
            litBranchName.Text = PartyOrgBranch.GetBranchBId(PartyJoinApplycation.BranchID).Rows[0]["BranchName"].ToString();
        }

        public DataTable GetJy()
        {
            var para = new List<MySqlParameter>
            {
                new MySqlParameter()
                {
                    DbType = DbType.String,
                    ParameterName = "AppllicationID",
                    Value = PartyJoinApplycation.AppllicationID
                }
            };
            string sql =
                @"SELECT MeetingTime, MeetingContent FROM tblpartyjoinmeetingex where StandID=(
SELECT StandID FROM tblpartyjoinlinkexample WHERE AppllicationID=?AppllicationID
AND CurrentStepID='JoinStep22' ORDER BY CreateTime DESC LIMIT 0,1
)";
            return ZHDJ.Data.MySqlHelper.ExecuteDataTable(sql, para.ToArray());
        }

        public string GetTanhua()
        {
            var para = new List<MySqlParameter>
            {
                new MySqlParameter()
                {
                    DbType = DbType.String,
                    ParameterName = "AppllicationID",
                    Value = PartyJoinApplycation.AppllicationID
                }
            };
            string sql =
                @"select Remark from tblpartyjoinlinkexample where CurrentStepID='JoinStep25' and AppllicationID=?AppllicationID ORDER BY CreateTime DESC LIMIT 0,1";
            return ZHDJ.Data.MySqlHelper.ExecuteScalar(sql, para.ToArray()).ToString();
        }
    }
}